*---------------------------------------------------------------------------------
** Paper: Redistributive Preferences?
** Authors: Lars Pelke
** Contact: lars.pelke@ipw.uni-heidelberg.de
** Journal: tba
** Replication: All tables and graphs in MANUSCRIPT

cd "insert your directory here"

***-----------------------------------------------------------*****
* Import Mulitple Imputated Datasets *

use "data\indoctrination_mechanisms\data1.dta", clear
mi import flongsep data_new5, using("data\indoctrination_mechanisms\data1.dta" "data\indoctrination_mechanisms\data2.dta" "data\indoctrination_mechanisms\data3.dta" "data\indoctrination_mechanisms\data4.dta" "data\indoctrination_mechanisms\data5.dta" "data\indoctrination_mechanisms\data6.dta" "data\indoctrination_mechanisms\data7.dta" "data\indoctrination_mechanisms\data8.dta" "data\indoctrination_mechanisms\data9.dta" "data\indoctrination_mechanisms\data10.dta") ///
 id(individual_id) imputed(education_3 unemployed income_deciles sex)
sleep 5000
mi convert mlong


***-----------------------------------------------------------*****
* Data management + 

gen dataset = 1 
replace dataset = 2 if data =="EVS"
replace dataset = 3 if data =="ESS"
replace dataset = 4 if data =="ISSP"
replace dataset = 5 if data =="Latinobarometer"

tab dataset

table(cohortmatch5_15)

table cohortmatch5_15 country_name


* generate Variables *

kdensity nationalist_5
gen nationalist_5_bin = cond(nationalist_5 > 0.66, 1, 0)
table(nationalist_5_bin) 

kdensity communist_5
gen communist_5_bin = cond(communist_5 > 0.66, 1, 0)
table(communist_5_bin) 

kdensity conservativ_5
gen conservativ_5_bin = cond(conservativ_5 > 0.66, 1, 0)
table(conservativ_5_bin) 

kdensity separatist_5
gen separatist_5_bin = cond(separatist_5 > 0.66, 1, 0)
table(separatist_5_bin) 

kdensity religious_5
gen religious_5_bin = cond(religious_5 > 0.66, 1, 0)
table(religious_5_bin) 


*center variables*

sum v2x_polyarchy, meanonly
gen v2x_polyarchy_c=v2x_polyarchy-r(mean)

sum e_migdppcln, meanonly
gen e_migdppcln_c=e_migdppcln-r(mean)


sum v2x_clphy_5, meanonly
gen v2x_clphy_5_c=v2x_clphy_5-r(mean)


sum v2exl_legitideol_5, meanonly
gen v2exl_legitideol_5_c=v2exl_legitideol_5-r(mean)

drop v2x_polyarchy e_migdppcln v2x_clphy_5 v2exl_legitideol_5
rename (v2x_polyarchy_c e_migdppcln_c v2x_clphy_5_c v2exl_legitideol_5_c) (v2x_polyarchy e_migdppcln v2x_clphy_5 v2exl_legitideol_5)

*additional variables*
sum nationalist_5, meanonly
gen nationalist_5_c=nationalist_5-r(mean)

sum communist_5, meanonly
gen communist_5_c=communist_5-r(mean)

sum conservativ_5, meanonly
gen conservativ_5_c=conservativ_5-r(mean)

sum separatist_5, meanonly
gen separatist_5_c=separatist_5-r(mean)

sum religious_5, meanonly
gen religious_5_c=religious_5-r(mean)

drop religious_5 separatist_5 conservativ_5 communist_5 nationalist_5
rename (religious_5_c separatist_5_c conservativ_5_c communist_5_c nationalist_5_c) (religious_5 separatist_5 conservativ_5 communist_5 nationalist_5)


* Model 2.1 - ideology + nationalist_5

	set more off
	mi estimate, post: xtmixed  red_pref age c.time_under_autocracy_15##c.v2exl_legitideol_5##i.nationalist_5_bin  ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m2a

outreg2 using Output/indoctrination_mechanism/Table2_1.doc, append ctitle(Model 2.1)

 estimates restore m2a
	mimrgns, at(time_under_autocracy_15 = (0 10 20 30 40 50 60) v2exl_legitideol_5 = (-1.814104 0 1.814104) nationalist_5_bin = (0 1)) atmeans cmdmargins
	marginsplot, by(v2exl_legitideol_5) ///
	xlabel(0 (10)60, angle(horizontal)labsize(small))   ///
	ylabel(38(2)48 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of nationalist ideology (at c)" "on redistribution preferences", size(medsmall)) ///
	xtitle("exposure to autocracy", size(medsmall))  ///
	legend(order( 3 "No nationalist ideology"  4 "Nationalist ideology" ) position(6) ring(0) )  ///
	title("", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4f, replace)
	
	graph save Output/indoctrination_mechanism/Figure2aMI, replace
	graph export Output/indoctrination_mechanism/Figure2aMI.pdf, replace
	
	
* Model 2.2- ideology + communist_5

	set more off
	mi estimate, post: xtmixed  red_pref age c.time_under_autocracy_15##c.v2exl_legitideol_5##i.communist_5_bin ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m2b

outreg2 using Output/indoctrination_mechanism/Table2_2.doc, append ctitle(Model 2.2)

 estimates restore m2b
	mimrgns, at(time_under_autocracy_15 = (0 10 20 30 40 50 60) v2exl_legitideol_5=(-1.814104 0 1.814104) communist_5_bin=(0 1)) atmeans cmdmargins
	marginsplot, by(v2exl_legitideol_5) ///
	xlabel(0 (10)60, angle(horizontal)labsize(small))   ///
	ylabel(38(2)48 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of communist ideology (at c)" "on redistribution preferences", size(medsmall)) ///
	xtitle("exposure to autocracy", size(medsmall))  ///
	legend(order( 3 "No communist ideology"  4 "Communist ideology" ) position(6) ring(0) )  ///
	title("", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4f, replace)
	
	graph save Output/indoctrination_mechanism/Figure2bMI, replace
	graph export Output/indoctrination_mechanism/Figure2bMI.pdf, replace
	
* Model 2.3 - ideology + conservativ_5

	set more off
	mi estimate, post: xtmixed  red_pref age c.time_under_autocracy_15##c.v2exl_legitideol_5##i.conservativ_5_bin ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m2c

outreg2 using Output/indoctrination_mechanism/Table2_3.doc, append ctitle(Model 2.2)

 estimates restore m2c
	mimrgns, at(time_under_autocracy_15 = (0 10 20 30 40 50 60) v2exl_legitideol_5=(-1.814104 0 1.814104) conservativ_5_bin=(0 1)) atmeans cmdmargins
	marginsplot, by(v2exl_legitideol_5) ///
	xlabel(0 (10)60, angle(horizontal)labsize(small))   ///
	ylabel(38(2)48 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of conservative ideology (at c)" "on redistribution preferences", size(medsmall)) ///
	xtitle("exposure to autocracy", size(medsmall))  ///
	legend(order( 3 "No conservative ideology"  4 "Conservative ideology" ) position(6) ring(0) )  ///
	title("", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4f, replace)
	
	graph save Output/indoctrination_mechanism/Figure2cMI, replace
	graph export Output/indoctrination_mechanism/Figure2cMI.pdf, replace

* Model 2.4 - ideology + conservativ_5

	set more off
	mi estimate, post: xtmixed  red_pref age c.time_under_autocracy_15##c.v2exl_legitideol_5##i.religious_5_bin ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m2d

outreg2 using Output/indoctrination_mechanism/Table2_4.doc, append ctitle(Model 2.2)

 estimates restore m2dd
	mimrgns, at(time_under_autocracy_15 = (0 10 20 30 40 50 60) v2exl_legitideol_5=(-1.814104 0 1.814104) religious_5_bin=(0 1)) atmeans cmdmargins
	marginsplot, by(v2exl_legitideol_5) ///
	xlabel(0 (10)60, angle(horizontal)labsize(small))   ///
	ylabel(38(2)48 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of religious ideology (at c)" "on redistribution preferences", size(medsmall)) ///
	xtitle("exposure to autocracy", size(medsmall))  ///
	legend(order( 3 "No religious ideology"  4 "Religious ideology" ) position(6) ring(0) )  ///
	title("", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4f, replace)
	
	graph save Output/indoctrination_mechanism/Figure2dMI, replace
	graph export Output/indoctrination_mechanism/Figure2dMI.pdf, replace
	


*---------------------------------------------------------------------------------
* Without Adequate Imputation 
** Paper: Redistributive Preferences?
** Authors: Lars Pelke
** Contact: lars.pelke@ipw.uni-heidelberg.de
** Journal: tba
** Replication: All tables and graphs in MANUSCRIPT

cd "M:/Promotion\Paper/WVS Redistribution in Autocracies/calculations_new"

***-----------------------------------------------------------*****
* Import Mulitple Imputated Datasets *

use "data\indoctrination_mechanisms\data1.dta", clear



***-----------------------------------------------------------*****
* Data management + 

gen dataset = 1 
replace dataset = 2 if data =="EVS"
replace dataset = 3 if data =="ESS"
replace dataset = 4 if data =="ISSP"
replace dataset = 5 if data =="Latinobarometer"

tab dataset

table(cohortmatch5_15)

table cohortmatch5_15 country_name

* generate Variables *

kdensity nationalist_5
gen nationalist_5_bin = cond(nationalist_5 > 0.66, 1, 0)
table(nationalist_5_bin) 

kdensity communist_5
gen communist_5_bin = cond(communist_5 > 0.66, 1, 0)
table(communist_5_bin) 

kdensity conservativ_5
gen conservativ_5_bin = cond(conservativ_5 > 0.66, 1, 0)
table(conservativ_5_bin) 

kdensity separatist_5
gen separatist_5_bin = cond(separatist_5 > 0.66, 1, 0)
table(separatist_5_bin) 

kdensity religious_5
gen religious_5_bin = cond(religious_5 > 0.66, 1, 0)
table(religious_5_bin) 


*center variables*

sum v2x_polyarchy, meanonly
gen v2x_polyarchy_c=v2x_polyarchy-r(mean)

sum e_migdppcln, meanonly
gen e_migdppcln_c=e_migdppcln-r(mean)


sum v2x_clphy_5, meanonly
gen v2x_clphy_5_c=v2x_clphy_5-r(mean)


sum v2exl_legitideol_5, meanonly
gen v2exl_legitideol_5_c=v2exl_legitideol_5-r(mean)

drop v2x_polyarchy e_migdppcln v2x_clphy_5 v2exl_legitideol_5
rename (v2x_polyarchy_c e_migdppcln_c v2x_clphy_5_c v2exl_legitideol_5_c) (v2x_polyarchy e_migdppcln v2x_clphy_5 v2exl_legitideol_5)

*additional variables*
sum nationalist_5, meanonly
gen nationalist_5_c=nationalist_5-r(mean)

sum communist_5, meanonly
gen communist_5_c=communist_5-r(mean)

sum conservativ_5, meanonly
gen conservativ_5_c=conservativ_5-r(mean)

sum separatist_5, meanonly
gen separatist_5_c=separatist_5-r(mean)

sum religious_5, meanonly
gen religious_5_c=religious_5-r(mean)

drop religious_5 separatist_5 conservativ_5 communist_5 nationalist_5
rename (religious_5_c separatist_5_c conservativ_5_c communist_5_c nationalist_5_c) (religious_5 separatist_5 conservativ_5 communist_5 nationalist_5)


* Model 2.1 - ideology + nationalist_5

	set more off
	xtmixed  red_pref age c.time_under_autocracy_15##c.v2exl_legitideol_5##i.nationalist_5_bin ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m2a

outreg2 using Output/indoctrination_mechanism/Table2_1.doc, append ctitle(Model 2.1)

 estimates restore m2a
	margins, at(time_under_autocracy_15 = (0 10 20 30 40 50 60) v2exl_legitideol_5 = (-1.814104 0 1.814104) nationalist_5_bin = (0 1)) atmeans
	marginsplot, by(v2exl_legitideol_5) ///
	xlabel(0 (10)60, angle(horizontal)labsize(small))   ///
	ylabel(38(2)48 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of nationalist ideology (at c)" "on redistribution preferences", size(medsmall)) ///
	xtitle("time under autocracy", size(medsmall))  ///
	legend(order( 3 "No nationalist ideology"  4 "Nationalist ideology" ) position(6) ring(0) )  ///
	title("", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4f, replace)
	
	graph save Output/indoctrination_mechanism/Figure2a, replace
	graph export Output/indoctrination_mechanism/Figure2a.pdf, replace
	
	
* Model 2.2 - ideology + communist_5

	set more off
	xtmixed  red_pref age c.time_under_autocracy_15##c.v2exl_legitideol_5##i.communist_5_bin ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m2b

outreg2 using Output/indoctrination_mechanism/Table2_2.doc, append ctitle(Model 2.2)

 estimates restore m2b
	margins, at(time_under_autocracy_15 = (0 10 20 30 40 50 60) v2exl_legitideol_5=(-1.814104 0 1.814104) communist_5_bin=(0 1)) atmeans 
	marginsplot, by(v2exl_legitideol_5) ///
	xlabel(0 (10)60, angle(horizontal)labsize(small))   ///
	ylabel(38(2)48 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of communist ideology (at c)" "on redistribution preferences", size(medsmall)) ///
	xtitle("time under autocracy", size(medsmall))  ///
	legend(order(3 "No communist ideology"  4 "Communist ideology" ) position(6) ring(0) )  ///
	title("", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4f, replace)
	
	graph save Output/indoctrination_mechanism/Figure2b, replace
	graph export Output/indoctrination_mechanism/Figure2b.pdf, replace

	
* Model 2.3 - ideology + conservativ_5_bin

	set more off
	xtmixed  red_pref age c.time_under_autocracy_15##c.v2exl_legitideol_5##i.conservativ_5_bin ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m2c

outreg2 using Output/indoctrination_mechanism/Table2_3.doc, append ctitle(Model 2.3)

 estimates restore m2c
	margins, at(time_under_autocracy_15 = (0 10 20 30 40 50 60) v2exl_legitideol_5=(-1.814104 0 1.814104) conservativ_5_bin=(0 1)) atmeans 
	marginsplot, by(v2exl_legitideol_5) ///
	xlabel(0 (10)60, angle(horizontal)labsize(small))   ///
	ylabel(38(2)48 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of conservative ideology (at c)" "on redistribution preferences", size(medsmall)) ///
	xtitle("time under autocracy", size(medsmall))  ///
	legend(order(3 "No conservative ideology"  4 "Conservative ideology" ) position(6) ring(0) )  ///
	title("", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4f, replace)
	
	graph save Output/indoctrination_mechanism/Figure2c, replace
	graph export Output/indoctrination_mechanism/Figure2c.pdf, replace

	